package com.spc.car.data.service.adm.impl;

import com.spc.car.data.domain.adm.vo.AdmVehlicePrivateVO;
import com.spc.car.data.entity.adm.AdmPrivateVehicleInfo;
import com.spc.car.data.mapper.adm.AdmPrivateVehicleInfoMapper;
import com.spc.car.data.service.adm.AdmPrivateVehicleInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.Objects;

/**
 * <p>
 * 私人车辆信息表 服务实现类
 * </p>
 *
 * @author 
 * @since 2020-04-30
 */
@Service
public class AdmPrivateVehicleInfoServiceImpl extends ServiceImpl<AdmPrivateVehicleInfoMapper, AdmPrivateVehicleInfo> implements AdmPrivateVehicleInfoService {


    @Override
    public boolean addOrUpdate(AdmVehlicePrivateVO vehlicePrivateVO) {
        AdmPrivateVehicleInfo privateVehicleInfo = new AdmPrivateVehicleInfo();
        BeanUtils.copyProperties(vehlicePrivateVO, privateVehicleInfo);

        if (!Objects.isNull(vehlicePrivateVO.getId())) {
            privateVehicleInfo.setUpdateTime(new Date());
            return updateById(privateVehicleInfo);
        }

        privateVehicleInfo.setCreateTime(new Date());
        return saveOrUpdate(privateVehicleInfo);
    }
}
